package com.thread;

/**
 * @Author WaveHi
 * @Date 18/8/2021 下午 9:15
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description
 */
public class TestMailman {

    public static void main(String[] args) {

        //获取快递员
        Mailman m1 = new Mailman("Tom");
        Mailman m2 = new Mailman("Betty");

        //开始派送快递
        m1.start();
        m2.start();

    }

}

//Expresses类
class Expresses {

    private String name;//快递名

    public Expresses() {

    }

    public Expresses(String name) {

        this.name = name;

    }

    public void setName(String name) {

        this.name = name;

    }

    public String getName() {

        return name;

    }

    public String toString() {

        return "Expresses{" + "name = " + name + "}";

    }

}

//Mailman类
class Mailman extends Thread {

    private String mailName;//快递员姓名

    public static Expresses[] ex;//快递
    static{

        ex = new Expresses[100];

        for(int i = 0;i < 100;i++) {

            ex[i] = new Expresses("Address:" + i);

        }

    }

    private static int index;//标记快递编号
    private int sum;//所派送的快递总数

    public Mailman() {

    }

    public Mailman(String mailName) {

        this.mailName = mailName;

    }

    public void setMailName(String milName) {

        this.mailName = mailName;

    }

    public String getMailName() {

        return mailName;

    }

    public void run() {



        while(true) {

            synchronized(Mailman.class) {

                if(index > 99) {

                    break;

                }


                System.out.println(getMailName() + " appaoched courier" +  " " + ex[index].getName());

                index++;

                sum++;
            }


        }





    }

}
